package com.along.game.action.manage;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.along.framework.utils.FgConstant;
import com.along.framework.utils.PatinationUtil;
import com.along.framework.web.BaseAction;
import com.along.game.model.SysInfo;
import com.along.game.service.GameConfigService;


public class SysInfoAction  extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3115605419729718059L;

	
	@Autowired
	private GameConfigService gameConfigService;
	private SysInfo   sysInfoVO;
	private Map if_using =new LinkedHashMap(); 
	public SysInfo getSysInfoVO() {
		return sysInfoVO;
	}


	public void setSysInfoVO(SysInfo sysInfoVO) {
		this.sysInfoVO = sysInfoVO;
	}


	public Map getIf_using() {
		return FgConstant.IF_USING;
	}


	public void setIf_using(Map if_using) {
		this.if_using = if_using;
	}

	/**
	 * 查询静态信息列表
	 */
	public String querySysInfo()
	{
	       HttpServletRequest request=getRequest();
			String currentpage=request.getParameter("currentpage");
	        int  totalRows =gameConfigService.querySysInfoCount(sysInfoVO);
			currentpage=PatinationUtil.getCurrentPage(currentpage);
			int startrow=PatinationUtil.getStartRow(currentpage);
			int endrow=PatinationUtil.getEndRow(currentpage);
			List sysInfoList =gameConfigService.querySysInfo(startrow, endrow, sysInfoVO);
			currentpage=PatinationUtil.getCurrentPage(currentpage);
            request.setAttribute("totalRows", totalRows);
			request.setAttribute("currentpage", currentpage);
			request.setAttribute("sysInfoList", sysInfoList);
	
return "/gameconfig/sysinfolist.jsp";
	}
	
	
	/**
	 * 进入静态信息修改页
	 */
	public String editSysInfo()
	{
	       HttpServletRequest request=getRequest();
		
			
			
			 if(sysInfoVO!=null)
			  {
				  request.setAttribute("addorupdate", "update");
				  sysInfoVO=gameConfigService.querySysInfoDetail(String.valueOf(sysInfoVO.getId()));
				
			  }
			  else{
		
				  request.setAttribute("addorupdate", "add");
			  }
				 
			
				
return "/baseinfo/gametableedit.jsp";
	}
	
	
	
	/**
	 * 执行修改、增加静态信息
	 * @return
	 * @throws IOException 
	 * @throws BusException
	 */
	public String postSysInfo() throws IOException{
	
	
	 HttpServletRequest request=getRequest();
 HttpServletResponse response=getResponse();
 String addorupdate=request.getParameter("addorupdate");
		String message="";
		if(addorupdate.equals("add"))
		{
			gameConfigService.loadSysInfo(sysInfoVO);
				message="添加成功";
				
		}
		else if(addorupdate.equals("update"))
		{
		
			gameConfigService.saveSysInfo(sysInfoVO);
				message="修改成功";
		
			
		}
		else  if(addorupdate.equals("remove")){
	
			gameConfigService.removeSysInfo(String.valueOf(sysInfoVO.getId()));
		
		
		message="删除成功";
		}
		 response.setContentType("text/html;charset=UTF-8");
		response.getWriter().println("<script>alert('"+message+"');this.location.href='bigPic_queryBigPic.do';</script>");
		response.flushBuffer();
		  return  null;
	
		//JSONUtil.writerJSON(list, response.getWriter(),java.util.Date.class);

	}
	
	
	
}
